home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3 / librw / RWTValHashMapIterator.z / RWTValHashMapIterator
Encoding:
Text File  |  2002-10-03  |  9.1 KB  |  265 lines

  1.  
  2.  
  3.  
  4. RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMaaaappppIIIItttteeeerrrraaaattttoooorrrr((((3333CCCC++++++++))))                        RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMaaaappppIIIItttteeeerrrraaaattttoooorrrr((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNaaaammmmeeee
  9.      RWTValHashMapIterator<K,T,H,EQ> - Rogue Wave library class
  10.  
  11. SSSSyyyynnnnooooppppssssiiiissss
  12.               #include<rw/tvhdict.h>
  13.  
  14.  
  15.  
  16.               RWTValHashMap<K,T,H,EQ> m;
  17.           RWTValHashMap<K,T,H,EQ> itr(m);
  18.  
  19. PPPPlllleeeeaaaasssseeee NNNNooootttteeee!!!!
  20.      IIIIffff yyyyoooouuuu hhhhaaaavvvveeee tttthhhheeee SSSSttttaaaannnnddddaaaarrrrdddd CCCC++++++++ LLLLiiiibbbbrrrraaaarrrryyyy,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ddddeeeessssccccrrrriiiibbbbeeeedddd hhhheeeerrrreeee....
  21.      OOOOtttthhhheeeerrrrwwwwiiiisssseeee,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ffffoooorrrr RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhDDDDiiiiccccttttiiiioooonnnnaaaarrrryyyyIIIItttteeeerrrraaaattttoooorrrr described
  22.      in Appendix A.
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
  30.      RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMaaaappppIIIItttteeeerrrraaaattttoooorrrr is supplied with Tools 7 to provide an iterator
  31.      interface to RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMaaaappppIIIItttteeeerrrraaaattttoooorrrr that has backward compatibility with
  32.      the container iterators provided in Tools 6. Iteration over an
  33.      RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMaaaapppp is pseudorandom and dependent on the capacity of the
  34.      underlying hash table and the hash function being used.  The only useable
  35.      relationship between consecutive elements is that elements which are
  36.      defined to be equivalent by the equivalence object, EEEEQQQQ, will remain
  37.      adjacent.  The current item referenced by this iterator is undefined
  38.      after construction or after a call to rrrreeeesssseeeetttt(((()))).  The iterator becomes
  39.      valid after being advanced with either a preincrement or an ooooppppeeeerrrraaaattttoooorrrr(((()))).
  40.      For both ooooppppeeeerrrraaaattttoooorrrr++++++++ and ooooppppeeeerrrraaaattttoooorrrr(((()))), iterating past the last element will
  41.      return a value equivalent to boolean ffffaaaallllsssseeee.  Continued increments will
  42.      return a value equivalent to ffffaaaallllsssseeee until rrrreeeesssseeeetttt(((()))) is called.
  43.  
  44. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee
  45.      None
  46.  
  47. EEEExxxxaaaammmmpppplllleeee
  48.               #include<rw/tvhdict.h>
  49.  
  50.  
  51.  
  52.               #include<iostream.h>
  53.           #include<rw/cstring.h>
  54.  
  55.  
  56.               struct silly_h{
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMaaaappppIIIItttteeeerrrraaaattttoooorrrr((((3333CCCC++++++++))))                        RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMaaaappppIIIItttteeeerrrraaaattttoooorrrr((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.                  unsigned long operator()(const RWCString& x) const
  75.              { return x.length() * (long)x(0); }
  76.           };
  77.  
  78.  
  79.               int main(){
  80.  
  81.  
  82.  
  83.                  RWTValHashMap
  84.                <RWCString,int,silly_h,equal_to<RWCString> > age;
  85.              RWTValHashMapIterator
  86.                <RWCString, int, silly_h, equal_to<RWCString > > itr(age);
  87.  
  88.  
  89.                  age.insert(RWCString("John"), 30);
  90.  
  91.  
  92.  
  93.                  age.insert(RWCString("Steve"),17);
  94.              age.insert(RWCString("Mark"),24);
  95.  
  96.  
  97.               //Duplicate insertion rejected
  98.  
  99.  
  100.  
  101.                  age.insert(RWCString("Steve"),24);
  102.  
  103.  
  104.  
  105.                  for(;itr();)
  106.  
  107.  
  108.  
  109.                    cout << itr.key() << "'s age is " << itr.value() << endl;
  110.  
  111.  
  112.  
  113.                  return 0;
  114.  
  115.  
  116.  
  117.               }
  118.  
  119.  
  120.  
  121.               Program Output (not necessarily in this order)
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMaaaappppIIIItttteeeerrrraaaattttoooorrrr((((3333CCCC++++++++))))                        RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMaaaappppIIIItttteeeerrrraaaattttoooorrrr((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140.               John's age is 30
  141.           Steve's age is 17
  142.           Mark's age is 24
  143.  
  144. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss
  145.               RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMaaaappppIIIItttteeeerrrraaaattttoooorrrr<<<<KKKK,,,,TTTT,,,,HHHH,,,,EEEEQQQQ>>>>
  146.  
  147.  
  148.  
  149.               (RWTValHashMap<K,T,H,EQ>&h);
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.      Creates an iterator for the hashmap hhhh.  The iterator begins in an
  157.      undefined state and must be advanced before the first element will be
  158.      accessible.
  159.  
  160. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr OOOOppppeeeerrrraaaattttoooorrrrssss
  161.               RWBoolean
  162.           ooooppppeeeerrrraaaattttoooorrrr(((())))();
  163.  
  164.  
  165.      Advances sssseeeellllffff to the next element. Returns ffffaaaallllsssseeee if the iterator has
  166.      advanced past the last item in the container and ttttrrrruuuueeee otherwise.
  167.  
  168.               RWBoolean
  169.           ooooppppeeeerrrraaaattttoooorrrr++++++++();
  170.  
  171.  
  172.      Advances sssseeeellllffff to the next element.  If the iterator has been reset or
  173.      just created sssseeeellllffff will now reference the first element.  If, before
  174.      iteration, sssseeeellllffff referenced the last association in the multimap, sssseeeellllffff
  175.      will now reference an undefined value and ffffaaaallllsssseeee will be returned.
  176.      Otherwise, ttttrrrruuuueeee is returned. Note: no postincrement operator is provided.
  177.  
  178. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
  179.               RWTValHashMap<K,T,H,EQ>*
  180.           ccccoooonnnnttttaaaaiiiinnnneeeerrrr(((()))) const;
  181.  
  182.  
  183.      Returns a pointer to the collection being iterated over.
  184.  
  185.               K
  186.           kkkkeeeeyyyy() const;
  187.  
  188.  
  189.      Returns the key portion of the association currently pointed to by sssseeeellllffff.
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMaaaappppIIIItttteeeerrrraaaattttoooorrrr((((3333CCCC++++++++))))                        RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMaaaappppIIIItttteeeerrrraaaattttoooorrrr((((3333CCCC++++++++))))
  203.  
  204.  
  205.  
  206.               void
  207.           rrrreeeesssseeeetttt();
  208.           void
  209.           rrrreeeesssseeeetttt(RWTValHashMap<K,T,H,EQ>& h);
  210.  
  211.  
  212.      Resets the iterator so that after being advanced it will reference the
  213.      first element of the collection.  Using rrrreeeesssseeeetttt(((()))) with no argument will
  214.      reset the iterator on the current container.  Supplying a RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhMMMMaaaapppp
  215.      to rrrreeeesssseeeetttt(((()))) will reset the iterator on that container.
  216.  
  217.               T
  218.           vvvvaaaalllluuuueeee();
  219.  
  220.  
  221.      Returns the value portion of the association referenced by sssseeeellllffff.
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.